home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / e / eiffel.lha / flc / framework / LIST < prev    next >
Encoding:
Text File  |  1996-01-26  |  929 b   |  45 lines

  1.  
  2. -- a LIST is a collection with fixed order.
  3. -- Elements can occur any number of times.
  4. -- Time complexity for data adding is O(1).
  5. -- Time complexity for data searching is O(n).
  6. -- Space complexity is O(n).
  7.  
  8. indexing
  9.  
  10.   names: list, chain;
  11.   contents: generic;
  12.  
  13.   author: "Guichard Damien";
  14.   created: 9,November,1995;
  15.   modified: 9,November,1995
  16.  
  17. class LIST inherit BAG
  18.   redefine add
  19.   end
  20. feature
  21.   add (element:BAG) is
  22.     -- Add an element to the list.
  23.     do
  24.       if next = Void then next := element end
  25.       if last /= Void then last.set_next(element)
  26.       last := element
  27.     end -- add
  28.   item (i:INTEGER):BAG is
  29.     -- Find i-th list item (from 1).
  30.     require -- i > 0
  31.     local n:INTEGER
  32.     do
  33.       from Result := Current
  34.       until n = i or Result = Void
  35.       variant -- i - n
  36.       loop
  37.         Result := Result.next
  38.         n := n + 1
  39.       end
  40.     end -- item
  41. feature{NONE}
  42.   last:BAG
  43. end -- class 'LIST'
  44.  
  45.